/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.NVBH;

import DAO.CTHoaDonDao;
import DAO.NhanVienDao;
import DAO.SanPhamDao;
import GUI.Var;
import POJO.NhanVien;
import POJO.SanPham;
import POJO.SanPhamBanTrongNgay;
//import POJO.SanPhamBanTrongNgay;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;
import javax.xml.bind.ParseConversionEvent;

/**
 *
 * @author Huê
 */
public class frLapBaoCaoBanTrongNgay extends javax.swing.JInternalFrame {

	/**
	 * Creates new form frLapBaoCaoBanTrongNgay
	 */
	//khai bao combobox model
	private DefaultComboBoxModel cbNVModel;

	public frLapBaoCaoBanTrongNgay() {
		initComponents();
		//   jlbTenNhanVien.setText();
		jTextField1.setText(Var.NV.getTenNV());
		// khoi tao combobox

	}

	private void loadSanPhamDaBan(int mnv) {
		ArrayList<SanPhamBanTrongNgay> dsSanPham = CTHoaDonDao.layDanhSachSanPhamDaBan(mnv);
		String[] columns = new String[]{"STT", "Sản phẩm", "Số lượng", "Đơn giá", "Thành tiền"};
		DefaultTableModel model = new DefaultTableModel(null, columns);
		int i = 1;
		for (SanPhamBanTrongNgay sp : dsSanPham) {
			Object[] items = new Object[]{i,
				sp.getTenSP(),
				sp.getSl(),
				sp.getGia(),
				sp.getThanhTien(),};
			i++;
			//int maLSP = sp.getMaLSP();
			model.addRow(items);
		}

		jtbDSMHDaBan.setModel(model);
		// Canh deu cac dong theo ti le % 10 % 30% 20%
		int[] va = {10, 30, 10, 20, 30};
		int[] pt = new int[5];
		for (int l = 0; l < 5; l++) {
			pt[l] = jtbDSMHDaBan.getWidth() * va[l] / 100;
			jtbDSMHDaBan.getColumnModel().getColumn(l).setPreferredWidth(pt[l]);

		}
	}

	/**
	 * This method is called from within the constructor to initialize the
	 * form. WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
       private void initComponents() {

              jPanel1 = new javax.swing.JPanel();
              jLabel5 = new javax.swing.JLabel();
              jPanel2 = new javax.swing.JPanel();
              jbtnLapBaoCao = new javax.swing.JButton();
              jlbTenNV = new javax.swing.JLabel();
              jlbTenNhanVien = new javax.swing.JLabel();
              jTextField1 = new javax.swing.JTextField();
              jPanel5 = new javax.swing.JPanel();
              jLabel7 = new javax.swing.JLabel();
              jLabel4 = new javax.swing.JLabel();
              jLabel1 = new javax.swing.JLabel();
              jLabel2 = new javax.swing.JLabel();
              lbTSSPDB = new javax.swing.JLabel();
              lbTTDB = new javax.swing.JLabel();
              lbTTDT = new javax.swing.JLabel();
              lbCT = new javax.swing.JLabel();
              jLabel9 = new javax.swing.JLabel();
              jLabel10 = new javax.swing.JLabel();
              jLabel11 = new javax.swing.JLabel();
              jLabel12 = new javax.swing.JLabel();
              jPanel3 = new javax.swing.JPanel();
              jScrollPane1 = new javax.swing.JScrollPane();
              jtbDSMHDaBan = new javax.swing.JTable();

              setClosable(true);
              setIconifiable(true);
              setMaximizable(true);
              setResizable(true);
              try {
                     setSelected(true);
              } catch (java.beans.PropertyVetoException e1) {
                     e1.printStackTrace();
              }

              jLabel5.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
              jLabel5.setText("LẬP BÁO CÁO BÁN HÀNG TRONG NGÀY");

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel5)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel1Layout.setVerticalGroup(
                     jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel5)
                            .addContainerGap())
              );

              jbtnLapBaoCao.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jbtnLapBaoCao.setText("Lập báo cáo");
              jbtnLapBaoCao.setToolTipText("gọi lập phiếu nhập kho");
              jbtnLapBaoCao.addActionListener(new java.awt.event.ActionListener() {
                     public void actionPerformed(java.awt.event.ActionEvent evt) {
                            jbtnLapBaoCaoActionPerformed(evt);
                     }
              });

              jlbTenNhanVien.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jlbTenNhanVien.setText("Nhân viên bán:");

              jTextField1.setEditable(false);

              javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
              jPanel2.setLayout(jPanel2Layout);
              jPanel2Layout.setHorizontalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGap(52, 52, 52)
                            .addComponent(jlbTenNV)
                            .addGap(215, 215, 215)
                            .addComponent(jlbTenNhanVien)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jbtnLapBaoCao)
                            .addGap(103, 103, 103))
              );
              jPanel2Layout.setVerticalGroup(
                     jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel2Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addComponent(jlbTenNV)
                                   .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                          .addComponent(jlbTenNhanVien)
                                          .addComponent(jbtnLapBaoCao)
                                          .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addContainerGap())
              );

              jLabel7.setText("Tổng tiền đã bán:");

              jLabel4.setText("Tổng số sản phẩm đã bán:");

              jLabel1.setText("Tổng tiền đã thu:");

              jLabel2.setText("Chưa thu:");

              lbTSSPDB.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbTSSPDB.setText("0");

              lbTTDB.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbTTDB.setText("0");

              lbTTDT.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbTTDT.setText("0");

              lbCT.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              lbCT.setText("0");

              jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel9.setText("VNĐ");

              jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel10.setText("VNĐ");

              jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel11.setText("VNĐ");

              jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
              jLabel12.setText("VNĐ");

              javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
              jPanel5.setLayout(jPanel5Layout);
              jPanel5Layout.setHorizontalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbTSSPDB)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbTTDB)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLabel12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbTTDT)
                            .addGap(22, 22, 22)
                            .addComponent(jLabel9)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(lbCT)
                            .addGap(23, 23, 23)
                            .addComponent(jLabel11)
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );
              jPanel5Layout.setVerticalGroup(
                     jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(jPanel5Layout.createSequentialGroup()
                            .addContainerGap()
                            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                   .addComponent(jLabel7)
                                   .addComponent(jLabel4)
                                   .addComponent(jLabel1)
                                   .addComponent(jLabel2)
                                   .addComponent(lbTSSPDB)
                                   .addComponent(lbTTDB)
                                   .addComponent(lbTTDT)
                                   .addComponent(lbCT)
                                   .addComponent(jLabel9)
                                   .addComponent(jLabel11)
                                   .addComponent(jLabel12)
                                   .addComponent(jLabel10))
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
              );

              jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách mặt hàng đã bán:"));
              jPanel3.setName(""); // NOI18N
              jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS));

              jtbDSMHDaBan.setModel(new javax.swing.table.DefaultTableModel(
                     new Object [][] {

                     },
                     new String [] {
                            "STT", "Sản phẩm", "Số lượng ", "Đơn giá", "Thành tiền"
                     }
              ));
              jScrollPane1.setViewportView(jtbDSMHDaBan);

              jPanel3.add(jScrollPane1);

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                   .addGroup(layout.createSequentialGroup()
                                          .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                          .addGap(1, 1, 1))
                                   .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                   .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
              );
              layout.setVerticalGroup(
                     layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(0, 0, 0)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 338, Short.MAX_VALUE)
                            .addGap(0, 0, 0)
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(0, 0, 0))
              );

              pack();
       }// </editor-fold>//GEN-END:initComponents

       private void jbtnLapBaoCaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnLapBaoCaoActionPerformed
		// TODO add your handling code here:
		int mnv = Var.NV.getMaNV();

		loadSanPhamDaBan(mnv);
		int soluong = CTHoaDonDao.TongSanPhamDaBanTrongNgay(mnv);
		lbTSSPDB.setText(String.valueOf(soluong));
		double tongtien = CTHoaDonDao.TongTienDaBanTrongNgay(mnv);
		lbTTDB.setText(String.valueOf(tongtien));
		double tongtiendathu = CTHoaDonDao.TongTienDaThuTrongNgay(mnv);
		lbTTDT.setText(String.valueOf(tongtiendathu));
		double tongtienchuathu = tongtien - tongtiendathu;
		lbCT.setText(String.valueOf(tongtienchuathu));
		
		


       }//GEN-LAST:event_jbtnLapBaoCaoActionPerformed

       // Variables declaration - do not modify//GEN-BEGIN:variables
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel10;
       private javax.swing.JLabel jLabel11;
       private javax.swing.JLabel jLabel12;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabel5;
       private javax.swing.JLabel jLabel7;
       private javax.swing.JLabel jLabel9;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel2;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanel5;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JTextField jTextField1;
       private javax.swing.JButton jbtnLapBaoCao;
       private javax.swing.JLabel jlbTenNV;
       private javax.swing.JLabel jlbTenNhanVien;
       private javax.swing.JTable jtbDSMHDaBan;
       private javax.swing.JLabel lbCT;
       private javax.swing.JLabel lbTSSPDB;
       private javax.swing.JLabel lbTTDB;
       private javax.swing.JLabel lbTTDT;
       // End of variables declaration//GEN-END:variables
}
